package com.zoroki.hmusic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zoroki.hmusic.entity.PlaylistSong;
import com.zoroki.hmusic.mapper.PlaylistSongMapper;
import com.zoroki.hmusic.service.IPlaylistSongService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zoroki
 * @since 2023-05-10
 */
@Service
@Slf4j
public class PlaylistSongServiceImpl extends ServiceImpl<PlaylistSongMapper, PlaylistSong> implements IPlaylistSongService {

    @Autowired
    private PlaylistSongMapper playlistSongMapper;

    @Override
    public List<PlaylistSong> findPlaylistSongByPlaylistId(int playlistId) {
        QueryWrapper<PlaylistSong> playlistSongQueryWrapper = new QueryWrapper<>();
        playlistSongQueryWrapper.eq("playlist_id", playlistId);
        return playlistSongMapper.selectList(playlistSongQueryWrapper);
    }

    @Override
    public int deleteSongFromPlaylist(int playlistId, int songId) {
        QueryWrapper<PlaylistSong> playlistSongQueryWrapper = new QueryWrapper<>();
        playlistSongQueryWrapper.eq("playlist_id", playlistId);
        playlistSongQueryWrapper.eq("song_id", songId);
        return playlistSongMapper.delete(playlistSongQueryWrapper);
    }

    @Override
    public int deletePlaylistSongByPlaylistId(int id) {
        QueryWrapper<PlaylistSong> wrapper = new QueryWrapper<>();
        wrapper.eq("playlist_id", id);
        return playlistSongMapper.delete(wrapper);
    }

    @Override
    public int deletePlaylistSongBySongId(int songId) {
        QueryWrapper<PlaylistSong> wrapper = new QueryWrapper<>();
        wrapper.eq("song_id", songId);
        return playlistSongMapper.delete(wrapper);
    }

    @Override
    public int addPlaylistSong(PlaylistSong playlistSong) {
        return playlistSongMapper.insert(playlistSong);
    }
}
